import * as echarts from '../../../ec-canvas/echarts';

const app = getApp();
const series = [{
  name: '高压(收缩压)mmHg',
  data: [130, 120, 102, 110, 134, 129, 120, 112, 133],
  // format: function (val, name) {
  //   return val.toFixed(2) + '万';
  // }
  type:'line',
  color: '#e92200',
  label: {
    normal: { show: true }
  }
}, {
  name: '低压(舒张压)mmHg',
  data: [73, 78, 82, 81, 82, 88, 82, 78, 80],
  // format: function (val, name) {
  //   return val.toFixed(2) + '万';
  // },
  type: 'line',
  color: "#50b025",
  label: {
    normal: { show: true }
  }
}, {
  name: '脉搏(次/分)',
  data: [70, 72, 76, 90, 78, 80, 73, 72, 71],
  // format: function (val, name) {
  //   return val.toFixed(2) + '万';
  // },
  type: 'line',
  color: "#f5d500",
  label: {
    normal: { show: true } 
  }
}];
const chartData = {
  legend: {
    orient: 'horizontal', // 'vertical'
    selected: {
      '降水量': false
    },
    data: [
      '最高气温', '最低气温'
    ],
    width: '100%',top: '12px', itemWidth: 10, itemHeight: 10
  },
  xAxis: {
    data: ['04/23', '04/23', '04/23', '04/23', '04/23', '04/23', '04/23'],
    type : 'category',
    boundaryGap: false,
    axisLabel: {
      interval: 0,
    },
    disableGrid: true,
  },
  tooltip: {
    trigger: 'axis',
  },
  
  yAxis: [
    {
      type: 'value',
      axisLabel: {
        formatter: '{value}'
      },
      min: function (value) {
        return value.min - 10;
      },
      interval: 10
    },
  ],
  series,
};
function initChart(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);

  var option = chartData;

  chart.setOption(option);
  return chart;
}

Page({
  onShareAppMessage: function (res) {
    return {
      title: 'ECharts 可以在微信小程序中使用啦！',
      path: '/pages/index/index',
      success: function () { },
      fail: function () { }
    }
  },
  data: {
    ec: {
      onInit: initChart
    }
  },

  onReady() {
  }
});
